﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
///NewsDetailDAL 的摘要说明
/// </summary>
public class NewsDetailDAL
{

    public List<News_Detail> PagingByTypeName(int pageIndex, int pageCount, out int count, string typeName)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("@pageIndex", SqlDbType.Int, pageIndex);
            tool.AddSqlParameter("@pageCount", SqlDbType.Int, pageCount);
            tool.AddSqlParameter("count", SqlDbType.Int, ParameterDirection.Output);
            tool.AddSqlParameter("type", SqlDbType.VarChar, 50, typeName);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "[News_Detail_Paging_typename]", tool.GetSqlParameters());
            count = (int)tool.GetSqlParameterByName("count").Value;
            DataTable tb = ds.Tables[0];
            List<News_Detail> lst = new List<News_Detail>();
            foreach (DataRow reader in tb.Rows)
            {
                News_Detail m = new News_Detail();
                m.Id = Tools.GetInt(reader["id"]);
                m.Title = Tools.GetString(reader["title"]);
                m.Text = Tools.GetString(reader["text"]);
                m.Typeid = Tools.GetInt(reader["typeid"]);
                m.Createdate = Tools.GetDateTime(reader["createdate"]);
                m.Countclick = Tools.GetInt(reader["countclick"]);
                m.Showontop = Tools.GetInt(reader["showontop"]);
                m.Url = Tools.GetString(reader["url"]);
                m.Ispublish = Tools.GetInt(reader["ispublish"]);
                m.Keywords = Tools.GetString(reader["keywords"]);
                m.Linktype = Tools.GetInt(reader["linktype"]);
                m.Titlefont = Tools.GetInt(reader["titlefont"]);
                lst.Add(m);
            }
            return lst;
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "PagingByTypeName", LogYuMin.LogStates.ERROR, ex);
            count = 0;
            return null;
        }
    }

    public DataTable GetNewsDetailByParam(NewDetailQuery q)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("sign", SqlDbType.Int, q.Sign);
            tool.AddSqlParameter("id", SqlDbType.Int, q.Id);
            tool.AddSqlParameter("typeid", SqlDbType.Int, q.TypeId);
            tool.AddSqlParameter("topnum", SqlDbType.Int, q.Topnum);
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, CommandType.StoredProcedure, "news_detail_select_w", tool.GetSqlParameters());
            return ds.Tables[0];
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "GetNewsDetailByParam", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
    }
}
